package www.rlicker.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import www.rlicker.dao.IFeedbackDao;
import www.rlicker.model.Feedback;
import www.rlicker.mybatis.Criteria;
import www.rlicker.service.IFeedbackService;
import www.rlicker.utils.MessageConstant;
import www.rlicker.utils.TranslateToMap;

/**
 * 
 * Feedback鏁版嵁搴撴搷浣滄帴鍙ｇ被
 * 
 **/

@Service
public class FeedbackServiceImpl implements IFeedbackService{


	public List<Map<String, Object>>  queryPage (Criteria<Feedback> param){
		List<Feedback> list = feedbackRepository.queryPage(param);
		List<Map<String,Object>> map = TranslateToMap.convertListBean2ListMap(list,Feedback.class);
	return map;  }

	public Integer queryPageCount (Criteria<Feedback> param){
		return (Integer) feedbackRepository.queryPageCount(param);
	}

	public Feedback  queryEntity (Long id ){
		return feedbackRepository.queryEntity(id);
	}

	public String deleteAll (String id ){
		List<Long> list = Arrays.asList(id.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
		int result = feedbackRepository.deleteAll(list);
		if ( result != 1) {
			return MessageConstant.USER_TYPE_3;
		}
		return null;
	}

	public String insert(Feedback record ){
		int result = feedbackRepository.insert(record);
			if ( result != 1) { 
					return null;
			}
			return MessageConstant.USER_TYPE_4;
	}

	public String update (Criteria<Feedback> param){
		int result = feedbackRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_5;
			}
			return null;
	}

	@Resource
	private IFeedbackDao feedbackRepository;

	@Override
	public List<Feedback> queryPageList(Criteria<Feedback> param) {
		return  feedbackRepository.queryPage(param);
	}

}